package com.geostar.constructionland.attachment.util;

import com.geostar.constructionland.attachment.config.StaticValue;

import java.util.Properties;


public class SystemGlobals {
	public static final String SYSTEM_GLOBALS_NAME = "SystemGlobals";

	private static Properties defaults = new Properties();

	private SystemGlobals() {
	}

	public static void setProperties(Properties properties) {
		defaults = properties;
		StaticValue.CLASS_PATH = getValue("CLASS_PATH", "DataServiceCenter2017_WEBROOT_PATH");
		StaticValue.SESSION_USER = getValue("SESSION_USER", "DataServiceCenter2017_user");
		StaticValue.SESSION_PERMISSIONS = getValue("SESSION_PERMISSIONS", "DataServiceCenter2017_permissions");
		StaticValue.SESSION_SOLR_EXIST = getValue("SESSION_SOLR_EXIST", "DataServiceCenter2017_SOLR_EXIST");
	}

	public static Properties getProperties() {
		return defaults;
	}

	public static String getValue(String key) {
		return defaults.getProperty(key);
	}

	public static String getValue(String key, String defaultValue) {
		String value = defaults.getProperty(key);
		if (value == null || "".equals(value)) {
			return defaultValue;
		}
		return value;
	}

	public static int getIntValue(String key, int defaultValue) {
		if (defaults.getProperty(key) == null) {
			return defaultValue;
		}
		try {
			return Integer.parseInt(defaults.getProperty(key));
		} catch (Exception e) {
			return defaultValue;
		}
	}
}
